package org.interfaceadaptation.test.notnull;

import java.util.Set;
import java.util.TreeSet;

public class ObjectCacheVerifier extends VerifierDecorator {
	
	private Set<Object> alreadyVerifiedObjects = new TreeSet<Object>();

	public ObjectCacheVerifier(Verifier verifier) {
		super(verifier);
	}

	@Override
	public boolean verify(Object element) {
		if (alreadyVerifiedObjects.contains(element)) {
			return true;
		}
		else {
			if (super.verify(element)) {
				alreadyVerifiedObjects.add(element);
				return true;
			}
			else {
			  return false;
			}
		}
	}
	
	protected void setAlreadyVerifiedObjects(Set<Object> alreadyVerifiedObjects) {
		this.alreadyVerifiedObjects  = alreadyVerifiedObjects;
	}
}
